/**
 * create by akon
 * date: 2016年12月3日22:17:50
 * js公共方法
 */
/**layer弹出层方法**/
function layerMsg(message) {
    layer.alert(message, {
        icon: 2,
        skin: 'layer-ext-moon'
    })
}
/**操作失败弹出提示**/
function failInLayer(message){
    layer.msg(message,{icon:2});
}
/**操作成功弹出提示**/
function successInLayer(message){
    layer.msg(message,{icon:1});
}
/**tips层**/
function layerTips(message,selector){
    layer.tips(message,selector);
}

/**序列化数据转换为Json格式**/
function getFormJson(form) {
    var o = {};
    //var a = $(form).serializeArray();
    $.each(form, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
}
/**去掉字符串前后所有空格**/
function Trim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
/**去掉字符串中所有空格**/
function TrimAll(str, is_global) {
    var result;
    result = str.replace(/(^\s+)|(\s+$)/g, "");
    if (is_global.toLowerCase() == "g") {
        result = result.replace(/\s/g, "");
    }
    return result;
}

/**jsencrypt加密**/
function encryptPass(password){
    //RSA私钥
    var pubkey='-----BEGIN PUBLIC KEY-----';
    pubkey+='MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAbfx4VggVVpcfCjzQ+nEiJ2DL';
    pubkey+='nRg3e2QdDf/m/qMvtqXi4xhwvbpHfaX46CzQznU8l9NJtF28pTSZSKnE/791MJfV';
    pubkey+='nucVcJcxRAEcpPprb8X3hfdxKEEYjOPAuVseewmO5cM+x7zi9FWbZ89uOp5sxjMn';
    pubkey+='lVjDaIczKTRx+7vn2wIDAQAB';
    pubkey+='-----END PUBLIC KEY-----';
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(pubkey);
    var encrypted = encrypt.encrypt(JSON.stringify({"encrypt": "yes", "password": password}));
    return encrypted;
}

/**异步跳转，不通过a标签**/
function goNextPage(url,id=0){
    window.location.href = url + "/id/" + id;
}

/**全选操作**/
function selectAllMenu(cName){
    $(this).bind("click",function(){
        $("."+ cName).prop("checked",true);
    })
}
/**取消全选**/
function selectNoMenu(cName){
    $(this).bind("click",function(){
        $("."+ cName).prop("checked",false);
    })
}
/**反选**/
function inverseSelect(cName){
    $(this).bind("click",function(){
        $("."+ cName).each(function(){
            this.checked = !this.checked;
        })
    })
}